package com.zryc.shop.pms.controller;

import com.zryc.shop.base.Result;
import com.zryc.shop.pms.entity.ProductAttribute;
import com.zryc.shop.pms.entity.ProductAttributeCategory;
import com.zryc.shop.pms.service.IProductAttributeCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 * 产品属性分类表 前端控制器
 * </p>
 *
 * @author zhaozhao
 * @since 2024-01-18
 */
@RestController
@Api(tags = "产品属性分类管理接口列表")
@RequestMapping("/pms/productAttribute/category")
public class ProductAttributeCategoryController {

    @Autowired
    private IProductAttributeCategoryService productAttributeCategoryService;

    @GetMapping("/list")
    @ApiOperation("分页查询列表")
    public Result list(@RequestParam(defaultValue = "1") @ApiParam(value = "页码", required = true) Integer pageNum,
                       @RequestParam(defaultValue = "5") @ApiParam(value = "每页大小", required = true) Integer pageSize) {
        return Result.ok(productAttributeCategoryService.categoryList(pageNum, pageSize));
    }

    @PostMapping("/update/{id}")
    @ApiOperation("修改属性分类名称")
    public Result updateById(@PathVariable Long id, @RequestParam String name) {
        return Result.ok(productAttributeCategoryService.categoryUpdateById(id, name));
    }
    @PostMapping("/create")
    @ApiOperation("创建属性分类")
    public Result create(@RequestParam @ApiParam(value = "属性分类名称", required = true) String name){
        return Result.ok(productAttributeCategoryService.create(name));
    }
    @GetMapping("/delete/{id}")
    @ApiOperation("删除属性分类")
    public Result delete(@PathVariable @ApiParam(value = "属性分类ID", required = true) Long id) {
        return Result.ok(productAttributeCategoryService.deleteAttributeCategory(id));
    }

    @GetMapping("/list/withAttr")
    @ApiOperation("属性分类")
    public Result withAttr() {
        return Result.ok(productAttributeCategoryService.withAttr());
    }

}
